{{ partial "header.html" . }}

<div id="loadingMask" style="width: 100%; height: 100%; position: fixed; background: #fff;"></div>
<script>
function fadeOut(el) {
  el.style.opacity = 1;

  var last = +new Date();
  var tick = function() {
    el.style.opacity = +el.style.opacity - (new Date() - last) / 80;
    last = +new Date();
    // console.log(el.style.opacity);

    if (el.style.opacity > 0) {
      (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16);
    } else {
      el.style.display='none';
    }
  };

  tick();
}

function ready(fn) {
    if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
         el = document.getElementById('loadingMask');
         fadeOut(el);
        var elements = document.querySelectorAll("img");
        Array.prototype.forEach.call(elements, function(el, i) {
            if (el.getAttribute("alt")) {
                const caption = document.createElement('figcaption');
                var node = document.createTextNode(el.getAttribute("alt"));
                caption.appendChild(node);
                const wrapper = document.createElement('figure');
                wrapper.className = 'image';
                el.parentNode.insertBefore(wrapper, el);
                el.parentNode.removeChild(el);
                wrapper.appendChild(el);
                wrapper.appendChild(caption);
            }
        });

    } else {
        document.addEventListener('DOMContentLoaded', fn);
    }
}
window.onload = ready;
</script>

<div class="content">
	<h1>{{ .Params.author }} </h1>
  {{ $guest := .Page.Params.author }}
  {{ .Content }}
  {{ $scratch := newScratch }}
  {{ $author := .Params.author }}
  {{ $scratch.Set "author" $author }}
  {{ $counter := 0 }}
  {{ range where .Site.RegularPages ".Type" "posts" }}
	{{ if (or (eq .Params.author ( $scratch.Get "author" )) (in .Params.authors ( $scratch.Get "author" )) ) }}
		{{ $counter = add $counter 1}}
	{{ end}}
  {{ end }}
  <h2> Contributions by {{ $guest }} ({{ $counter }}):</h2>
  <div class="preview">
  {{ range $pageName := .Site.RegularPages }}
	  {{ if and (eq .Type "posts") ( or (in .Params.author $guest) (in .Params.authors $guest)) }}
		<p>
		<aside>{{ .Date.Format "January 2, 2006"}} 
			{{ if not (eq .Params.tags nil) }}
				{{ range first 2 .Params.tags }}
					<a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}/" style="text-decoration:none">#{{ lower . }}</a>
				{{ end }}
				{{ if gt (len .Params.tags) 2 }}
					...
				{{ end }}
			{{ end }}
		</aside>
		
		<a href="{{ .Permalink }}">{{ .Title }}</a>{{ if .Draft }} <span style="color:#FF4136;">(unpublished)</span>{{ end }}</p>
	  {{ end }}
  {{ end }}
  </div>

  <hr>
  See all <u><a href="{{ .Site.BaseURL }}authors/">contributing authors</a></u>.
</div>

<!--
{{ partial "latest_comments" . }}
-->

